﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StationaryRequest.DTO;

namespace StationaryRequest.DAL
{
    public interface ICategoriesRepository
    {
        void AddStationaryCategory( StationaryCategory stationarycategory );
        void RemoveStationaryCategory( string name );
        IEnumerable<CategoryDTO> GetCategories();
    }

    public class CategoriesRepository : ICategoriesRepository
    {
        private InventoryModelContainer context;

        public CategoriesRepository( InventoryModelContainer inventorymodel )
        {
            context = inventorymodel;
        }

        public void AddStationaryCategory( StationaryCategory stationarycategory )
        {
            throw new NotImplementedException();
        }

        public void RemoveStationaryCategory( string name )
        {
            throw new NotImplementedException();
        }

        public IEnumerable<CategoryDTO> GetCategories()
        {
            List<CategoryDTO> stationarycategories = new List<CategoryDTO>();

            stationarycategories = context.StationaryCategories
                .ToList()
                .ConvertAll( x => HydrateCategoryDTO( x ) );

            return stationarycategories;
        }

        private CategoryDTO HydrateCategoryDTO( StationaryCategory categoryDAL )
        {
            return new CategoryDTO( categoryDAL.Name, categoryDAL.Description );
        }
    }
}
